package com.bwie.mq;

import cn.hutool.core.util.RandomUtil;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @className: MqConsumer
 * @Description: TODO
 * @version: v1.８.0
 * @author: 安楷杰
 * @date: 2025/11/6 21:03
 */
@Component
public class MqConsumer {
    @Autowired
    private RedisTemplate redisTemplate;

    public static final String CODE_NUMBER = "phone_code";//发送短信(key)
    @RabbitListener(queuesToDeclare = @Queue("sendCode2"))
    public void sendCode(String phoneNumber){
        //生成验证码
        String code = RandomUtil.randomNumbers(4);
        //存入redis
        redisTemplate.opsForValue().set(CODE_NUMBER + phoneNumber,code,2, TimeUnit.MINUTES);

        System.out.println(code);
        //发送验证码
//       sendSmsUtils.sendSms(phoneNumber, JSONObject.toJSONString(new HashMap<String,String>(){{
//           put("code",code);
//       }}));
    }
}